package work.sajor.wechatpush.job;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.extra.mail.MailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import work.sajor.wechatpush.service.Pusher;

import java.util.Date;

/**
 * @ClassName JobWorker
 * @Description TODO
 * @Author ydzhao
 * @Date 2022/8/2 16:00
 */
@Component
public class JobWorker {
    /**
     * 要推送的用户openid
     */
    @Value("${target.openId}")
    private String openId;

    @Autowired
    Pusher pusherService;

    //每天 8点 12点 21点执行定时任务
    @Scheduled(cron = "0 0 8,12,21 * * ? ")
    public void goodMorning() {
        pusherService.push(openId);
    }

    //每天 8点 12点 21点执行定时任务
    @Scheduled(cron = "0 0 8,12,21 * * ? ")
    public void sendMail() {
        //考研时间:
        String dateStr1 = "2022-12-24 00:00:00";
        Date date1 = DateUtil.parse(dateStr1);
        //相差一个月，31天
        long betweenDay = DateUtil.between(date1, new Date(), DateUnit.DAY);
        System.out.println(betweenDay);
        String nowTime = DateUtil.format(new Date(), "yyyy/MM/dd");

        MailUtil.send("2889214077@qq.com", nowTime,
                "<div style=\"border: 1px solid #ccc;width: 200px;background-color: rgb(54, 153, 224);color: azure;padding: 20px;\">\n" +
                        "        <b>大宝卫鹏过来提醒你啦！</b>\n" +
                        "        <div>\n" +
                        "            <b>距离考研还剩：</b>\n" + "<b style='color:#D82A20'>" + betweenDay + "天</b>" +
                        "        </div>\n" +
                        "        <div style=\"margin-top: 10px;\">一定要加油喔！！！</div>\n" +
                        "    </div>",
                true);
    }

}
